(function(win) {
  var doc = win.document
  var docEl = doc.documentElement
  var tid

  function refreshRem() {
    var width = docEl.getBoundingClientRect().width
    var height = document.body.clientHeight
    var scaleWin = height / width
    var scaleImg = 1334 / 750
    var scale = parseFloat(scaleImg.toFixed(2)) / parseFloat(scaleWin.toFixed(2))
    scale = scale > 1 ? scale : 1
    
    if (width > 750) { // 最大宽度
      width = 750
    }
    var rem = width / 10 // 将屏幕宽度分成10份， 1份为1rem
    docEl.style.fontSize = rem/scale + 'px'
  }

  win.addEventListener('resize', function() {
    clearTimeout(tid)
    tid = setTimeout(refreshRem, 300)
  }, false)
  win.addEventListener('pageshow', function(e) {
    if (e.persisted) {
      clearTimeout(tid)
      tid = setTimeout(refreshRem, 300)
    }
  }, false)

  refreshRem()

})(window)